import type { EventBus } from 'quasar';
import type { InjectionKey } from 'vue';

export const tokenKey = 'token';
export const userKey = 'user';

// 基础字段填充
export const baseFiled = {
  createBy: '',
  createTime: '',
  updateBy: '',
  updateTime: '',
  id: '',
};

export const eventBusKey: InjectionKey<EventBus<Api.EventBusType>> = Symbol();

/* WebSocket 收到消息的类型 */
export enum MsgType {
  /* 新的私信 */
  refreshChat = 'refreshChat',
}

export function replaceText(val: string) {
  if (val != null && val != '') {
    const re1 = new RegExp('<.+?>|&.+?;', 'g');
    let msg = val.replace(re1, ''); //执行替换成空字符
    //  msg = msg.replace(/\s/g, ''); //去掉所有的空格（中文空格、英文空格都会被替换）
    msg = msg.replace(/[\r\n]/g, ''); //去掉所有的换行符
    return msg;
  } else return '';
}

/* 校验密码强度 */
export function checkPd(s: string) {
  const regex = /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]{8,}$/;
  return regex.test(s);
}
